package org.example.demo3.demos.web.VmsTransactionFlowInvoice.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.demo3.demos.web.VmsTransactionFlowInvoice.domain.*;
import org.example.demo3.demos.web.VmsTransactionFlowInvoice.service.VmsTransactionFlowInvoiceService;
import org.example.demo3.demos.web.common.Result;
import org.example.demo3.demos.web.model.dto.vmstransactionflowinvoice.VmsTransactionFlowInvoiceDto;
import org.example.demo3.demos.web.model.negativestream.vmstransactionflowinvoice.VmsManualInvoiceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // 1. 必须写,不然无法放到ioc容器里,会报错404
@Api("发票匹配流水-列表")
@RequestMapping("/transactionFlowInvoice")
@Slf4j
public class VmsTransactionFlowInvoiceController {
    @Autowired
    VmsTransactionFlowInvoiceService vmsTransactionFlowInvoiceService;
           @Autowired
   private RedisTemplate<String, Object> redisTemplate;

    @ApiOperation("列表层")
    @PostMapping("/list")
    //        只能传递{
//    "pageNo": 1,
//    "pageSize":2,
//    "endTime": "2024-06-30",
//    "startTime": "2024-05-01"   -- 这里不能多余的 ,逗号
//}
//        if(dto.getPageNo() == 0 || dto.getPageSize() == 0){
//            throw new BaseException("没对象");
//        }
    public Result<IPage<VmsTransactionFlowInvoicePageVo>> list(@RequestBody VmsTransactionFlowInvoicePageDto dto){
        log.error("-----错误信息",dto);
        // try{
        //     int i = 1/0;
        // }catch (Exception e){
        //     log.error("eeeeee 1/0",e);

        // }
        Integer pageNo = dto.getPageNo();
        Integer pageSize = dto.getPageSize();
        Page<VmsTransactionFlowInvoicePageVo> page = new Page<>(pageNo, pageSize);
        Result<IPage<VmsTransactionFlowInvoicePageVo>> transactionFlowInvoiceList = vmsTransactionFlowInvoiceService.getTransactionFlowInvoiceList(dto,page);

        return  transactionFlowInvoiceList;
    }

    @PostMapping("/preMerge")
    public Result<List<VmsMergeBo>> PreMerge(@RequestBody preMergeDTO dto){
        Result<List<VmsMergeBo>>  bo= vmsTransactionFlowInvoiceService.preMerge(dto);
        return  bo;
    }


    @PostMapping("/checkFlowInvoiceStatus")
    public Result<Object> checkFlowInvoiceStatus(@RequestParam String id){
        System.out.println(id);
        return  vmsTransactionFlowInvoiceService.checkFlowInvoiceStatus(id);

    }
    @PostMapping("/mergeQuery")
    public Result<IPage<VmsMergeQueryVo>> mergeQuery(@RequestBody preMergeDTO dto){
        return  vmsTransactionFlowInvoiceService.mergeQuery(dto);
    }

    @PostMapping(value = "/merge")
    public Result<Object> getVmsTransactionFlowInvoiceService(@RequestBody preMergeDTO dto) {
        log.info("传入的对象",dto);
        return vmsTransactionFlowInvoiceService.merge(dto);
    }
    @PostMapping(value = "/getMergeSplitInfo")
    public Result<VmsFlowInvoiceDetailVo> getMergeSplitInfo(@RequestParam String rdid) {
        System.out.println(rdid);
        Result<VmsFlowInvoiceDetailVo> mergeSplitInfo = vmsTransactionFlowInvoiceService.getMergeSplitInfo(rdid);
        return mergeSplitInfo;
    }
    @PostMapping(value = "/getMergeSplitItem")
    public Result<IPage<VmsFlowInvoiceDetailVo>> getMergeSplitItem(@RequestBody preMergeDTO dto) {
        Result<IPage<VmsFlowInvoiceDetailVo>> mergeSplitItem = vmsTransactionFlowInvoiceService.getMergeSplitItem(dto);
        return mergeSplitItem;
    }


    // 还原 - 确认按钮
    @PostMapping(value = "/restoreFlow")
    public Result<Object> restoreFlow(@RequestParam String rdid) {
        System.out.println(rdid);
        Result<Object> objectResult = vmsTransactionFlowInvoiceService.restoreFlow(rdid);
        return objectResult;
    }
    // 开发票 前的查询发票信息 111
    @PostMapping(value = "/getInvoiceInfoByTransactionFlow")
    public Result<VmsManualInvoiceVo> getInvoiceInfoByTransactionFlow(@RequestBody List<Long> ids) {
        //        // 设置键值对
//       redisTemplate.opsForValue().set("key", "value1");
//
//       // 获取值
//       String value = (String) redisTemplate.opsForValue().get("key");
//        System.out.println(ids);
        Result<VmsManualInvoiceVo> objectResult = vmsTransactionFlowInvoiceService.getInvoiceInfoByTransactionFlow(ids);
        System.out.println(objectResult);
        return objectResult;
    }
    @PostMapping(value = "/splitTransactionFlow")
    public Result<Object> splitTransactionFlow(@RequestBody VmsFlowSplitDto dto) {
        Result<Object> objectResult = vmsTransactionFlowInvoiceService.splitTransactionFlow(dto);
        return objectResult;
    }





    @PostMapping(value = "/invoiceByTransactionFlow01")
    public Result<Object> invoiceByTransactionFlow01(@RequestBody VmsTransactionFlowInvoiceDto dto){
        Result<Object> objectResult = vmsTransactionFlowInvoiceService.invoiceByTransactionFlow(dto);
        return  Result.OK("你好");
    }
    @PostMapping(value = "/invoiceByTransactionFlow02")
    public Result<Object> invoiceByTransactionFlow02(@RequestBody VmsTransactionFlowInvoiceDto dto){
        Result<Object> objectResult = vmsTransactionFlowInvoiceService.invoiceByTransactionFlow(dto);
        return  Result.OK("你好");
    }

























}
